package com.example.xunai.dto.request.ai;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ChatRequest {
    @NotBlank(message = "用户消息不能为空")
    private String userMessage;

    private String sessionId;

    private Long conversationId;

    @NotNull(message = "用户ID不能为空")
    private Long userId;

    @NotBlank(message = "模型类型不能为空")
    private String modelType;

    public static ChatRequest of(String userMessage, String sessionId,
                                 Long conversationId, Long userId, String modelType) {
        return new ChatRequest(userMessage, sessionId, conversationId, userId, modelType);
    }

    public boolean isValid() {
        return userMessage != null && !userMessage.trim().isEmpty()
                && userId != null && modelType != null;
    }

    public String toLogString() {
        return String.format("ChatRequest{userId=%s, conversationId=%s, model=%s, messageLength=%d}",
                userId, conversationId, modelType,
                userMessage != null ? userMessage.length() : 0);
    }
}